package com.deer.wms.system.manage.web;

import com.deer.wms.project.root.util.RedisUtil;
import com.deer.wms.system.manage.model.SysParamDetail;
import com.deer.wms.system.manage.model.SysParamDetailCriteria;
import com.deer.wms.system.manage.model.SysParamDto;
import com.deer.wms.system.manage.service.SysParamDetailService;
import com.deer.wms.system.manage.service.SysParamService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2019/07/12.
*/
@Api(description = "系统参数详细信息api接口")
@RestController
@RequestMapping("/sys/param/details")
public class SysParamDetailController {

    @Autowired
    private SysParamDetailService sysParamDetailService;

    @Autowired
    private SysParamService sysParamService;

    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/save")
    public Result add(@RequestBody SysParamDetail sysParamDetail) {
        sysParamDetailService.save(sysParamDetail);
        sysParamService.reSetRedis();
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete( Integer id) {
        sysParamDetailService.removeById(id);
        sysParamService.reSetRedis();
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody SysParamDetail sysParamDetail) {
        sysParamDetailService.updateById(sysParamDetail);
        sysParamService.reSetRedis();
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        SysParamDetail sysParamDetail = sysParamDetailService.getById(id);
        //sysParamService.reSetRedis();
        return ResultGenerator.genSuccessResult(sysParamDetail);
    }

    @GetMapping("/list")
    public Result list(SysParamDetailCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SysParamDetail> list = sysParamDetailService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        //sysParamService.reSetRedis();
        return ResultGenerator.genSuccessResult(pageInfo);
    }








}
